import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { $t } from '#/locales';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'userId',
      label: $t('views.system.oauth2.token.userId'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.system.oauth2.token.userIdPlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'userType',
      label: $t('views.system.oauth2.token.userType'),
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.USER_TYPE, 'number'),
        placeholder: $t('views.system.oauth2.token.userTypePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'clientId',
      label: $t('views.system.oauth2.client.clientId'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.system.oauth2.client.clientIdPlaceholder'),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'accessToken',
      title: $t('views.system.oauth2.token.accessToken'),
      minWidth: 300,
    },
    {
      field: 'refreshToken',
      title: $t('views.system.oauth2.token.refreshToken'),
      minWidth: 300,
    },
    {
      field: 'userId',
      title: $t('views.system.oauth2.token.userId'),
      minWidth: 100,
    },
    {
      field: 'userType',
      title: $t('views.system.oauth2.token.userType'),
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.USER_TYPE },
      },
    },
    {
      field: 'clientId',
      title: $t('views.system.oauth2.client.clientId'),
      minWidth: 120,
    },
    {
      field: 'expiresTime',
      title: $t('views.system.oauth2.token.expiresTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'createTime',
      title: $t('common.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.action'),
      width: 100,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
